{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602\spatial_4_spgen_overlap_grid_1702.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}20 Feb 2023, 16:11:26
{txt}
{com}. 
. global matrix "R:\WSV2\TBu_AKe\Spatial_NEW\Grid_4950" 
{txt}
{com}. cd "$matrix" // set working directory 
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_4950
{txt}
{com}. 
. 
. 
. cd // display in log file       
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_4950
{txt}
{com}.         
. 
.         *************************************
.         ** 1) W matrix, save vertical only **
.         *************************************
. 
. use spatial_3_wmat_grid_polar 
{txt}
{com}. 
. 
. keep cell a_bin r_* // reduce 
{txt}
{com}. 
. rename r_* v_* // rename the vertical matrix 
{res}{txt}
{com}. 
. preserve 
{txt}
{com}. 
. keep cell a_bin v* 
{txt}
{com}. 
. save "$store\wmat_vert_grid.dta", replace 
{txt}{p 0 4 2}
file {bf}
R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602\wmat_vert_grid.dta{rm}
saved
{p_end}

{com}. 
. restore 
{txt}
{com}. 
. clear 
{txt}
{com}. 
. 
.                 *******************************
.                 ****  2) Load Grid Sections ***
.                 *******************************
.                 
. cd "$store"
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{txt}
{com}.                 
. 
. forvalues q = 5(5)40 {c -(}
{txt}  2{com}.         
.         use "R:\WSV2\TBu_AKe\Spatial_NEW\Grid_4950\spatial_3_wmat_grid_`q'.dta" 
{txt}  3{com}.         
.         keep cell o* w* 
{txt}  4{com}.         merge 1:1 cell using wmat_vert_grid 
{txt}  5{com}. 
.                 forvalues j = 1/4950 {c -(}
{txt}  6{com}.                 
.                         capture quietly replace w`q'_`j' = 0 if v_`j' == 1
{txt}  7{com}.                         capture quietly replace o`q'_`j' = 0 if v_`j' == 1
{txt}  8{com}.         
.         {c )-}
{txt}  9{com}.         
.         xtset cell 
{txt} 10{com}.         spset cell // must by spset. 
{txt} 11{com}. 
.         cd "$store"
{txt} 12{com}. 
.                         *** O
.         spmatrix fromdata O`q' = o`q'_1 - o`q'_4950, normalize(none) 
{txt} 13{com}. 
.         spmatrix save O`q' using O`q'.stswm, replace // inverse: spmatrix use
{txt} 14{com}. 
.                         *** W
.         spmatrix fromdata W`q' = w`q'_1 - w`q'_4950, normalize(none) 
{txt} 15{com}. 
.         spmatrix save W`q' using W`q'.stswm, replace // inverse: spmatrix use
{txt} 16{com}. 
.         clear 
{txt} 17{com}.                 
. {c )-}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_5.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O5} saved in file {bf:O5.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W5} saved in file {bf:W5.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_10.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O10} saved in file {bf:O10.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W10} saved in file {bf:W10.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_15.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O15} saved in file {bf:O15.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W15} saved in file {bf:W15.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_20.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O20} saved in file {bf:O20.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4904 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W20} saved in file {bf:W20.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_25.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4908 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O25} saved in file {bf:O25.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4910 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W25} saved in file {bf:W25.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_30.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4912 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O30} saved in file {bf:O30.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4914 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W30} saved in file {bf:W30.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_35.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4916 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O35} saved in file {bf:O35.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4918 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W35} saved in file {bf:W35.stswm}){p_end}
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}           4,950{txt}  (_merge==3)
{col 5}{hline 41}

{col 1}Panel variable: {res}cell{txt} (balanced)
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_40.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{p 2 2 2}{txt}(weighting matrix contains 4922 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:O40} saved in file {bf:O40.stswm}){p_end}
{res}{p 2 2 2}{txt}(weighting matrix contains 4924 islands){p_end}
{res}{p 2 2 2}{txt}(matrix {bf:W40} saved in file {bf:W40.stswm}){p_end}

{com}. 
.                 *** add the horizontal matrix *** 
.         use "R:\WSV2\TBu_AKe\Spatial_NEW\Grid_4950\spatial_3_wmat_grid_polar.dta" 
{txt}
{com}.         
.         keep cell r* h* 
{txt}
{com}.         rename r_* v_* // rename the vertical matrix 
{res}{txt}
{com}.         *merge 1:1 cell using wmat_vert_grid // not needed, same dataset 
. 
.                 forvalues j = 1/4950 {c -(}
{txt}  2{com}.                 
.                         capture quietly replace h_`j' = 0 if v_`j' == 1
{txt}  3{com}.         
.         {c )-}
{txt}
{com}.         
.         xtset cell 

{txt}{col 1}Panel variable: {res}cell{txt} (balanced)

{com}.         spset cell // must by spset. 
{res}
{txt}{ralign 16:Sp dataset}: {res:spatial_3_wmat_grid_polar.dta}
Linked shapefile: <none>
{ralign 16:Data}: Cross sectional
{ralign 16:Spatial-unit ID}: {res:_ID} (equal to {res:cell})
{ralign 16:Coordinates}: <none>

{com}. 
.         cd "$store"
{res}R:\WSV2\TBu_AKe\Spatial_NEW\Grid_overlap_1602
{txt}
{com}. 
.                         *** Rook
.         spmatrix fromdata R = v_1 - v_4950, normalize(none) 
{res}{p 2 2 2}{txt}(weighting matrix contains 4900 islands){p_end}

{com}. 
.         spmatrix save R using R.stswm, replace // inverse: spmatrix use
{res}{p 2 2 2}{txt}(matrix {bf:R} saved in file {bf:R.stswm}){p_end}

{com}. 
.                         *** Horizontal
.         spmatrix fromdata H = h_1 - h_4950, normalize(none) 
{res}{p 2 2 2}{txt}(weighting matrix contains 4902 islands){p_end}

{com}. 
.         spmatrix save H using H.stswm, replace // inverse: spmatrix use
{res}{p 2 2 2}{txt}(matrix {bf:H} saved in file {bf:H.stswm}){p_end}

{com}. 
.         clear 
{txt}
{com}.         capture log close 
{smcl}
{com}{sf}{ul off}